# -*- coding: utf-8 -*-
"""
    Data: 2022/6/13
    Time: 22:35
    Author: Driving
"""
from PyQt5.Qt import *
import sys
import typing
from resources.register import Ui_Form


class RegisterPage(QWidget, Ui_Form):

    exit_signal = pyqtSignal()
    register_signal = pyqtSignal(str, str)

    def __init__(self, parent=None, *args, **kwargs):
        super(RegisterPage, self).__init__(parent, *args, **kwargs)
        self.setAttribute(Qt.WA_StyledBackground, True)  # 默认背景关闭，需要手动设置
        self.setupUi(self)
        self.setWindowTitle("Register-Page")
        self.animation_targets = [self.exit_menu_btn, self.reset_menu_btn, self.about_menu_btn]
        self.animation_targets_pos = [target.pos() for target in self.animation_targets]

    def edit_menu(self, checked):

        animation_group = QSequentialAnimationGroup(self)
        for idx, target in enumerate(self.animation_targets):
            animation = QPropertyAnimation()
            animation.setTargetObject(target)  # 设置子控件
            animation.setPropertyName(b"pos")
            animation.setStartValue(self.main_menu_btn.pos())
            animation.setEndValue(self.animation_targets_pos[idx])
            animation.setDuration(120)
            animation.setEasingCurve(QEasingCurve.OutSine)
            animation_group.addAnimation(animation)

        if not checked:
            animation_group.setDirection(QAbstractAnimation.Forward)
        else:
            animation_group.setDirection(QAbstractAnimation.Backward)

        animation_group.start(QAbstractAnimation.DeleteWhenStopped)

    def exit_menu(self):
        self.exit_signal.emit()

    def reset_menu(self):
        self.account_le.clear()
        self.pw_le.clear()
        self.comfirm_pw_le.clear()

    def about_menu(self):
        QMessageBox.about(self, "Driving", "详情请关注'https://gitee.com/zihaodl/detect_app'")

    def register_main(self):
        account_txt = self.account_le.text()
        pw_txt = self.pw_le.text()
        self.register_signal.emit(account_txt, pw_txt)

    def enable_register(self):
        account_txt = self.account_le.text()
        pw_txt = self.pw_le.text()
        comfirm_pw_txt = self.comfirm_pw_le.text()
        #
        if len(account_txt) > 0 and 0 < len(pw_txt) == len(comfirm_pw_txt) > 0:
            self.register_btn.setEnabled(True)
        else:
            self.register_btn.setEnabled(False)


if __name__ == '__main__':

    app = QApplication(sys.argv)
    window = RegisterPage()

    window.show()
    sys.exit(app.exec_())